//************************************************************
//
// DATASTEP 1. BUILDING TECHNO PATENT DATABASE
//
// DATASOURCE: USPTO
//
// AUTHOR: LIONEL NESTA
//
//*************************************************************

// PREAMBLE

clear
clear matrix 
clear mata
set more off
set mem 2500m
set matsize 800
cd "USPTO_SOURCE"

// WORKING ON SOURCE FILE

// PATENT YEAR

use pat_year.dta, clear
append using pat_year_00_06.dta
duplicates drop
sort patnum
save pat_year_all.dta, replace

// PATENT TECHNOLOGY

use pat_ec.dta, clear
append using pat_ec_00_06.dta
duplicates drop
sort patnum

// REDUCING TO 3-DIGIT TECHNOLOGY 

gen ec3 =  substr(ec,1,3)  		
drop ec
duplicates drop	

save pat_ec_all.dta, replace		

// MERGING WITH PAT_YEAR

mmerge patnum using pat_year_all.dta, type(n:1)
drop _merge

// AND SAVING

save pat_ec_year.dta, replace

